
#ifndef GPS_PROTO_GPS_PARSER_H__
#define GPS_PROTO_GPS_PARSER_H__

#include <string>
#include "expat_handler.h"

namespace gps_proto {

class GpsProto;
class TrackProto;
class SegmentProto;
class PointProto;

class GpsParser : public ExpatHandler {
 public:
  GpsParser(GpsProto* gps_proto);

  static bool ParseFromFile(const char* filename, GpsProto* gpx_proto);
  static bool ParseFromIstream(std::istream* input, GpsProto* gpx_proto);
  static bool ParseFromString(const std::string& gpx, GpsProto* gpx_proto);

  // ExpatHandler::CharData()
  virtual void CharData(const XML_Char* str, int len);

  static bool ParseLatLonAttrs(const char** atts, PointProto* point_proto);

 protected:
  void GatherCharData();
  const std::string& GetCharData() const;

  // The output proto.
  GpsProto* gps_proto_;
  // Current <Lap>
  TrackProto* track_proto_;
  // Current <Track>
  SegmentProto* segment_proto_;
  // Current <Trackpoint>
  PointProto* point_proto_;

 private:
  bool gather_char_data_;
  // Current character data.
  std::string char_data_;
};

}  // end namespace gps_proto

#endif  // GPS_PROTO_GPS_PARSER_H__
